<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.net.URLDecoder" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>教务辅助管理系统_登录</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="lib/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/lib/sweetalert/sweetalert.css">
<link rel="stylesheet" href="css/login.css"></link>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<% 
		request.setCharacterEncoding("UTF-8");
		Cookie[] cookie=request.getCookies(); //从request中获取Cookies集
		String username=null;
		String password=null;
		if(cookie!=null&&cookie.length>1) {
			for (Cookie c : cookie) {  
				//获取对应cookie的信息
		        if ("username".equals(c.getName())) {  
		        	username=c.getValue();
		        	username=URLDecoder.decode(username,"utf-8"); //解码
		        }  
		        else if("password".equals(c.getName())){
		        	password=c.getValue();
		        }
		    } 
		}
	%>
<div class="top-content">
    <div class="container">
        <div class="row">
            <div class="text-center">
                <h2>教务辅助管理系统</h2>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6 col-sm-offset-3 form-box">
            	<div class="form-top">
            		<div class="col-sm-4 form-title">
            			<i class="fa fa-user"></i> 登陆
            		</div>
            		<div class="col-sm-4 col-sm-offset-4">
            			<a href="register.jsp" class="text-primary pull-right">注册</a>
            		</div>
                </div>
                <div class="form-bottom">
              		<form name="loginform" role="form" action="login" method="post" class="login-form" onsubmit="return check(this);">
              			<div class="form-group">
              				<label class="sr-only" for="form-username">学号</label>
                  			<input type="text" name="username" value="<%=username==null?"":username%>" placeholder="请输入学号/工号" class="form-username form-control" id="form-username">
                  		</div>
                  		<div class="form-group margin-top">
                  			<label class="sr-only" for="form-password">密码</label>
                  			<input type="password" name="password" value="<%=password==null?"":password%>" placeholder="请输入密码" class="form-password form-control" id="form-password">
                  		</div>
                  		<div class="checkbox c-checkbox">
	                        <label>
	                        	<input type="checkbox" checked="checked" name="isremember" value="true">
	                           <span class="fa fa-check"></span>记住我</label>
                     	</div>              	
                  		<button type="submit" class="btn btn-block margin-top">登陆</button>
                  		<div class="clear"></div>
              		</form>
             	</div>
            </div>
        </div>
    </div>   
</div>
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="<%=request.getContextPath()%>/lib/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" >
	//表单提交前进行数据验证，数据合法则返回true表单提交
	function check(loginform) {  
		if(loginform.username.value=="") {
			swal("学号/工号不能为空", "请重新输入", "warning")
    		return false;
    	}
    	else if(!isNumber(loginform.username.value)) {
    		swal("学号/工号不合法","请重新输入","warning");  
	        return false;  
    	}
    	else if(loginform.password.value=="" || loginform.password.value.length<6) {
    		swal("密码长度不小于6","请重新输入","warning");  
	        return false; 
    	}
    	else {
    		if(document.getElementByName("isremember").checked){
    			loginform.isremember.value = true;
			}
			else {
				loginform.isremember.value = false;
			}
    		return true; 
    	} 
	}   
	  
	function isNumber(str)          // 判断是否为非负整数  
	{  
	    var rx = /^[0-9]+$/;  
	    return rx.test(str);  
	} 
	
	<%
	String error = (String)session.getAttribute("error");
	if(error != null) {%>
		swal("失败", "<%=error%>", "warning");
		<%session.removeAttribute("error");
	} %>
</script>
</body>
</html>